package logconfig

import (
	_ "embed"
	"gitee.com/zaper/service-center-client/util"
	"gopkg.in/natefinch/lumberjack.v2"
	"strconv"
)

//go:embed config/logconfig.properties
var config string

type LogConfig struct{}

func NewLogConfig() *LogConfig {
	return &LogConfig{}
}

func (LogConfig *LogConfig) GetConfig() *lumberjack.Logger {
	var logConfig = &lumberjack.Logger{}
	pies, err := util.ParseStringToProperties(config)
	if err != nil {
		println("config read fail")
		return nil
	}
	logConfig.Filename = pies.Data["Filename"]

	maxSize, _ := strconv.Atoi(pies.Data["MaxSize"])
	logConfig.MaxSize = maxSize

	maxBackups, _ := strconv.Atoi(pies.Data["MaxBackups"])
	logConfig.MaxBackups = maxBackups

	maxAge, _ := strconv.Atoi(pies.Data["MaxAge"])
	logConfig.MaxAge = maxAge

	compress, _ := strconv.ParseBool(pies.Data["Compress"])
	logConfig.Compress = compress
	return logConfig
}
